<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app"></div>
    <template id="t1">
      <div>
        <button @click="add">新增元素</button>
        <ul>
          <li v-for="(item,index) of hobbys" :id="item+index">
            {{item}}-{{index}}
          </li>
        </ul>
      </div>
    </template>
    <script src="./vue.js"></script>
    <script>
      // 数据驱动视图
      const vm = new Vue({
        el: "#app",
        template: "#t1",
        data: {
          hobbys: ["css", "html", "js", "vue", "git"],
        },
        methods: {
          add() {
            // this.hobbys.push("git");
            // this.hobbys.splice(3, 0, "git");
            // this.hobbys = [...this.hobbys, "vue"];

            // this.hobbys = this.hobbys.filter((el, i) => i % 2 === 0);
            this.hobbys = this.hobbys.concat("vuex", "router");
          },
        },
      });
    </script>
  </body>
</html>
